<script type="text/javascript">
function checkImageExt(obj) {
	var t = obj.value;
	var txt = obj.value.substring(obj.value.lastIndexOf(".")+1).toLowerCase();
	if(!(txt == "jpg" || txt == "jpeg" || txt == "gif" || txt == "png" || txt == "swf")) {
		alert("ไฟล์ที่แนบมาไม่ถูกต้อง " + t + "\nกรุณาเลือกไฟล์ใหม่");	
		u = document.getElementById('uploader');
		u.innerHTML=' <input name="txtFiles" id="txtFiles" type="file" style="width:300px;" onchange="checkImageExt(this);" /> ';
	}
}
</script>

<div id="mainContent">
	<form  name="myForm" id="myForm" enctype="multipart/form-data" method="post" action="<?=site_url()?>banner/upload">
		<input name="position" type="hidden" id="position" value="<?php if(isset($banner['position'])) echo $banner['position']; ?>"/>
		<table width="800px" align="center" cellpadding="2" cellspacing="2" style="border: 1px solid #0000FF; background-color: #FFFFFF">
		  <col width="170px" />
		  <col width="*" />
		  <tr bgcolor="#000974">
		    <td colspan="2" align="left" bgcolor="#000974" style="color:#FFFFFF;"><label>.:: จัดการแบนเนอร์หน้าแรก</label></td>
		  </tr>
		  <tr>
		    <td align="right"><label>รูปภาพปัจจุบัน</label></td>
		    <td align="left">
		      <?php if(isset($banner['file_name'])) {
		      			if(strpos($banner['file_name'], ".swf") > 0) {
		      				// flash player
		      				echo '<object width="550" height="130">
								    <param name="movie" value="'. $banner['file_name'] .'">
								    <embed src="'. site_url() . 'data-image/file_management/' . $banner['file_name'] .
								    '" width="550" height="130">
								    </embed>
								</object>';
		      			} else {
		      				// image
		      				echo '<img src="'. site_url() . 'data-image/file_management/' . $banner['file_name']  .'" width="550" height="130" />';
		      			}	
		      		}
		      ?>    
		    </td>
		  </tr>
		  <tr>
		    <td align="right"><label>ไฟล์ใหม่</label></td>
		    <td align="left">
		    	<div id="uploader">
		    		ขนาดไฟล์ที่เหมาะสม (กว้าง 550px, สูง 130px)<br/>
		      		<input name="txtFiles" id="txtFiles" type="file" style="width:300px;" onchange="checkImageExt(this);" />
		      	</div>   
		 	</td>
		  </tr>
		  <tr>
		    <td align="right">&nbsp;</td>
		    <td align="left">
		    	<input type="submit" name="button" id="button" value="บันทึกข้อมูล" />
		    </td> 
		  </tr>
		  <tr style="height:10px;">
		    <td colspan="2"></td>
		  </tr>
		</table>
	</form>
</div>
